<template>
	<view class="homeLayout pageBg">
		<custom-nav-bar title="推荐"></custom-nav-bar>
		
		<view class="select">
			<common-title>
				<template #name>
					每日推荐
				</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
						</view>
					</view>
				</template>
			</common-title>
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="item in randomImages" @click="goPreview(item.id)">
						<image :src="item.pic" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="theme">
			<common-title>
				<template #name>专题精选</template>
				<template #custom>
					<navigator url="/pages/classify/classify" class="more">More+</navigator>
				</template>
			</common-title>
			<view class="content">
				<theme-item v-for="item in classifyList" :key="item.id" :item="item"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onReady } from '@dcloudio/uni-app'
import { apiGetRandomImages, apiGetClassify } from '@/api/apis';

const randomImages = ref([]);
const classifyList = ref([]);
// 每日推荐
const getRandomImages = async() => {
	let res = await apiGetRandomImages();
	randomImages.value = res.data;
}
// 获取分类列表
const getClassify = async() => {
	let res = await apiGetClassify();
	classifyList.value = res.data;
}
	
onReady(() => {
	getRandomImages();
	getClassify();
})

const goPreview = (id) => {
	uni.setStorageSync("storageClassList", randomImages.value)
	uni.navigateTo({
		url:"/pages/preview/preview?id=" + id
	})
}
</script>

<style lang="scss" scoped>
	.homeLayout {
		.select {
			padding-top: 50rpx;
			.date{
				color: $brand-theme-color;
				display: flex;
				align-items: center;
				:deep(){
					.uni-icons{
						color: $brand-theme-color !important;
					}
				}
				.text{
					margin-left: 5rpx;
				}
			}
			.content {
				width: 720rpx;
				margin-left: 30rpx;
				margin-top: 30rpx;
				scroll-view {
					white-space: nowrap;
					.box {
						width: 200rpx;
						height: 430rpx;
						display: inline;
						margin-right: 15rpx;
						image {
							width: 200rpx;
							height: 430rpx;
							border-radius: 10rpx;
						}
					}
					.box:last-child{
						margin-right: 30rpx;
					}
				}
			}
		}
		.theme{
			padding: 50rpx 0;
			.more{
				font-size: 31rpx;
				color: #888;
			}
			.content {
				margin-top: 30rpx;
				padding: 0 30rpx;
				display: grid;
				gap: 10rpx;
				grid-template-columns: repeat(3,1fr);
			}
		}
	}
</style>
